package procesos;

import java.io.IOException;
import java.io.InputStream;

public class Procesos {

    public static void main(String[] args) throws IOException, InterruptedException {

        Runtime r = Runtime.getRuntime();
        r.addShutdownHook(new Final());

        Process proceso = r.exec("cmd /C dir");
        Thread.sleep(1000);
        InputStream is = proceso.getInputStream();
        while (is.available() > 0) {
            System.out.print((char) is.read());
        }

        proceso.waitFor();
        System.out.println("ACABO: " + proceso.exitValue());

//            ls -l | more

    }

    static class Final extends Thread {

        public void run() {
            System.out.println("Finalizando!!!");
        }
    }
}
